# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__="修改俱乐部信息"
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest

import random
        
class Club_ModifyClubInfo(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))

        clubName = "AT_"
        if "clubName" in args:
            clubName = args["clubName"]

        clubHomePageLayer = poco("ClubHomePageLayer")

        if not clubHomePageLayer.exists():
            return False

        btnMyCreateNor = poco("my_create_nor")
        btnMyCreatePress = poco("my_create_press")
        if not btnMyCreatePress.exists() and btnMyCreateNor.exists():
            self.clickButton(btnMyCreateNor)

        myCreateList = clubHomePageLayer.offspring("my_create_list")
        clubItems = myCreateList.offspring("my_create_item")
        for item in clubItems:
            txtName = item.offspring("club_name").get_text()
            if txtName.startswith(clubName):
                self.clickButton(item)
                break

        try:
            poco("ClubPageLayer").wait_for_appearance()
        except:
            return False

        clubPageLayer = poco("ClubPageLayer")
        btnInfoNormal = clubPageLayer.offspring("info_normal")
        btnInfoSelect = clubPageLayer.offspring("info_select")

        # 切换到俱乐部管理面板
        if not btnInfoSelect.exists():
            self.clickButton(btnInfoNormal)

        clubInfoLayer = clubPageLayer.offspring("club_info_panel")
        txtClubName = clubInfoLayer.offspring("club_name_text")
        self.clickButton(txtClubName)

        strNewClubName = "AT_" + str(random.randint(1001, 2000))

        createLayer = clubPageLayer.offspring("ClubCreatePageLayer")

        txtNewClubName = createLayer.offspring("club_name")
        txtNewClubName.set_text("")
        self.clickButton(txtNewClubName)
        text(strNewClubName)

        txtNewClubDesc = createLayer.offspring("club_desc")
        txtNewClubDesc.set_text("")
        self.clickButton(txtNewClubDesc)
        text(strNewClubName)

        btnSave = createLayer.offspring("club_create_btn")
        self.clickButton(btnSave)

        txtClubName = clubInfoLayer.offspring("club_name_text")
        strSaveClubName = txtClubName.get_text();
        assert_equal(strSaveClubName, strNewClubName, "修改俱乐部信息成功")

        btnBack = clubPageLayer.offspring("back_btn")
        if btnBack.exists():
            self.clickButton(btnBack)

        return True
        
_instance = Club_ModifyClubInfo()
runTest = _instance.runTest
